package com.peng.service;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.peng.mapper.ArticleMapper;
import com.peng.pojo.Article;
import com.peng.pojo.ArticleType;
import com.peng.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleServiceImp implements ArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public PageInfo<Article> selectAll(String title, Integer publisherId, Integer typeId, Integer page, Integer size) {
        if (page != null && size != null) {
            PageHelper.startPage(page, size);
        }
        return new PageInfo<>(articleMapper.selectAll(title, publisherId, typeId));
    }

    @Override
    public boolean updateArticleStatus(int status, Integer... id) {
        if (id != null) {
            articleMapper.updateArticleStatus(status, id);
        }
        return true;
    }

    @Override
    public List<User> selectAllUser() {
        return articleMapper.selectAllUser();
    }

    @Override
    public List<ArticleType> selectAllArticleType() {
        return articleMapper.selectAllArticleType();
    }

    @Override
    public List<Article> selectBroadcastingArticle() {
        return articleMapper.selectBroadcastingArticle();
    }

    @Override
    public List<Article> selectArticleByTimeDesc() {
        return articleMapper.selectArticleByTimeDesc();
    }

    @Override
    public List<ArticleType> selectArticleTypeAndArticle() {
        return articleMapper.selectArticleTypeAndArticle();
    }

    @Override
    public List<Article> selectArticleByTypeId(int typeId) {
        return articleMapper.selectArticleByTypeId(typeId);
    }
}
